<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
    
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7">
        <title>平台代买页面</title>
        <jsp:include page="../lbi/css.jsp"></jsp:include>
        <link rel="stylesheet" href="<c:url value="/static/css/member.css"/>"/>
    </head>
    
    <body>  
        <div class="wrap">
            <!-- 头部开始-->
            <jsp:include page="../lbi/head.jsp"></jsp:include>
            <!-- 头部结束-->
            
            <div class="nav_bottom common"></div>
            <div class="main common clearfix">
                <!-- 工作台开始 -->
                <jsp:include page="../lbi/workbench.jsp"></jsp:include>
                <!-- 工作台结束 -->
                
                <div class="right-content fr">
                    <div class="header-tips">
                        <h1>发布求购信息 </h2>
                        <h2>温馨提示：请填写真实货物信息，如果发布不合法规的货物信息，一经发现将被失去买家会员资格。</h3>
                    </div>
                    <div class="form">
                        <table>
                            <tbody>
                                <tr>
                                    <th><span>*</span>交易方式&nbsp;: </th>
                                    <td>
                                    <input type="radio" checked  name="qg" id="xhqg" onclick="if(this.checked){forBuy()}" value="1" /><label for="xhqg">现货求购</label>
                                    <input name="qg"  type="radio" id="qghy" onclick="if(this.checked){yellowPageBuy()}" value="2" /><label for="qghy">求购黄页</label> 
                                    <input name="qg" type="radio" id="ptdm" onclick="if(this.checked){platformBuy()}" value="3" /><label for="ptdm">平台代买</label>
                                    </td>
                                </tr>
                                <tr>
                                    <th><span>*</span>货物名称&nbsp;: </th>
                                    <td>
                                    <input class="inputClass" type="text" placeholder="求购"  id="forBuy" />
                                    <span class="tips" id="forBuyError"></span>
                                    </td>
                                </tr>
                                    <tr>
                                    <th><span>*</span>货物类型&nbsp;: </th>
                                    <td class="relative">
                                       <input class="select-res" type="text" placeholder="请选择货物类型"  id="forType" />
                                       <span class="tips" id="forTypeError"></span>
                                       <div class="select-box" id="category_ch">
                                        <span class="close-btn">×</span>
                                        <div class="type-list">
                                            <ul class="first" id="first"></ul>
                                            <ul class="second" id="second"></ul>
                                            <ul class="third" id="third"></ul>
                                        </div>
                                    </div>
                                    </td>
                                </tr>
                                <tr>
                                    <th><span>*</span>货物数量&nbsp;: </th>
                                    <td>
                                        <input class="inputClass" type="text"  id="goodsQuantity" onkeyup="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}"
	onafterpaste="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'0')}else{this.value=this.value.replace(/\D/g,'')}" />
                                        <select  id="unit" class="unit">
                                          <option value="">选择单位</option>
                                          <option value="辆">辆</option>
                                          <option value="吨">吨</option>
                                          <option value="台">台</option>
                                          <option value="个">个</option>
                                          <option value="千克">千克</option>
                                          <option value="桶">桶</option>
                                          <option value="盒">盒</option>
                                          <option value="套">套</option>
                                          <option value="米">米</option>
                                          <option value="平方米">平方米</option>
                                          <option value="批">批</option>
                                        </select>
                                         <span class="tips none" id="unitError">请选择单位</span>
                                        <div><span class="tips" id="goodsQuantityError"></span></div>
                                    </td>
                                </tr>
                                <tr>
                                    <th><span>*</span>目标单价&nbsp;: </th>
                                    <td>
                                    <input type="radio"checked  name="mbdj" id="dy" value="1" /><label for="dy">电议</label>
                                    <input name="mbdj"  type="radio" id="jt" value="2" /><label for="jt">具体值 </label>
                                    <input type="text" class="m_num inputClass" id="money" disabled onkeyup="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}"
	onafterpaste="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'0')}else{this.value=this.value.replace(/\D/g,'')}" />&nbsp;&nbsp;<label>元</label>
                                    <span class="tips" id="moneyError"></span>
                                    </td>
                                </tr>
                                    <tr>
                                        <th><span>*</span>收货地址&nbsp;: </th>
                                        <td>
                                            <div class="fl" id="r-result" style="width:500px;">
                                                <input type="text" class="inputClass" id="suggestId" size="20" placeholder="输入街道、乡镇、小区或商圈名称" " />
                                                <span class="tips" id="suggestIdError"></span>
                                            </div>
                                            <div id="container"></div>
                                            <div id='pointBox'></div>
                                        </td>
                                    </tr>
                                <tr>
                                    <th><span>*</span>运送方式&nbsp;: </th>
                                    <td>
                                    <input type="radio"checked  name="ysfs" id="shsm" value="1" /><label for="shsm">送货上门</label>
                                    <input name="ysfs"  type="radio" id="smzt" value="2" /><label for="smzt">上门自提</label>
                                    </td>
                                </tr>   
                                <tr>
                                    <th><span>*</span><b class="date-warn">报价截止时间</b>&nbsp;: </th>
                                    <td>
                                    <input type="text" class="" id="date" placeholder="yyyy-MM-dd"/><span class="tips" id="dateError"></span>
                                    </td>
                                </tr>
                                <tr height="80px"><td colspan="2"><hr/></td></tr>
                                <tr>
                                    <th><span>*</span>账期要求&nbsp;: </th>
                                    <td>
                                    <input type="radio" checked  name="zqyq" id="df" value="1" /><label for="df">货到付款</label>
                                    <input name="zqyq"  type="radio" id="zq" value="2" /><label for="zq">可接受账期</label>
                                    </td>
                                </tr>
                                <tr>
                                    <th><span>*</span>发票要求&nbsp;: </th>
                                    <td>
                                    <input type="radio" checked  name="fpyq" id="yf" value="1" /><label for="yf">可提供发票</label>
                                    <input name="fpyq"  type="radio" id="nf" value="2" /><label for="nf">无要求</label>
                                    </td>
                                </tr>
                                <tr>
                                    <th><span></span>所在地要求&nbsp;: </th>
                                    <td>
                                    <input type="text" id="addressRequire"/>
                                    </td>
                                </tr>
                                <tr>
                                    <th><span></span>其他说明&nbsp;: </th>
                                    <td>
                                    <textarea class="other-text" id="otherText"></textarea>
                                    </td>
                                </tr>
                                <tr height="80px"><td colspan="2"><hr/></td></tr>
                                <tr>
                                    <th valign="top"><span>*</span>货物图片&nbsp;: </th>
                                    <td>
                                      <div class="fl" id="Pic_pass">
                                        <div class="picDiv">
                                            <div class="addImages">
                                                
                                                <input type="file" class="file" id="fileInput" accept="image/png, image/jpeg, image/gif, image/jpg">
                                                <div class="text-detail">
                                                    <span>+</span>
                                                    <p>添加电脑图片</p>
                                                </div>
                                            </div>
                                        </div>
                                        <p>(最少上传一张，格式不小于350X350px,支持jpg、png、bmp格式，单个文件小于5M)</p>
                                    </div>
                                    <div class="msg" style="display: none;"></div>
                                    </td>
                                </tr>
                                <tr>
                                    <th valign="top"><span></span>货物描述&nbsp;: </th>
                                    <td width="740px">
                                    <script id="editor" type="text/plain" style="width:100%;height:300px; float: left;">
                                    </script>
                                    <div class="none" id="introdution"></div>
                                    </td>
                                </tr>
                                <tr>
                                    <th></th>
                                    <td><input class="sumit_btn" type="button" id="btn_register" value="立即发布" /></td>
                                </tr>
                            </tbody>
                        </table>
                        
                        <input type="hidden" id="strJson"  value='${dataJson}'/>
                        
                    </div>
                </div>
            </div>

            <footer class="common">
                <div class="footer-top">
                    <ul>
                        <li class="plqq">
                            <span class="icon"></span>
                            <h1>品种规格齐全</h1>
                        </li>
                        <li class="zzbz">
                            <span class="icon"></span>
                            <h1>质量可靠保障</h1>
                        </li>
                        <li class="jgyz">
                            <span class="icon"></span>
                            <h1>价格占有优势</h1>
                        </li>
                        <li class="qqbt">
                            <span class="icon"></span>
                            <h1>缺钱可打白条</h1>
                        </li>
                        <li class="mfzc">
                            <span class="icon"></span>
                            <h1>免费找货找车</h1>
                        </li>
                    </ul>
                </div>
                <div class="footer-bottom">
                    <h1 class="common tc">Copyright©right;2018 www.zaishengwang.com Inc. All rights reserved</h1>
                    <h2 class="common tc">苏ICP证161025号 | 苏ICP备15001001号 | 再生网</h2>
                </div>
            </footer>
        </div>
        
       <script type="text/javascript" src="<c:url value="/static/js/member/forBuy.js"/>"></script>
       <script type="text/javascript">
        function forBuy(){
                $(".date-warn").text("报价截止日期");
                $("div.form tbody tr").removeClass('none');
        }
        function yellowPageBuy(){
              $("div.form tbody tr").removeClass('none');
              $("div.form tbody tr").each(function(){
                  $(".date-warn").text("有效期");
                  if($(this).index()>7 &&$(this).index()<13){
                      $(this).addClass('none');
                      $("div.form tbody tr:last-child").removeClass('none');
                  };
                });
        }
        function platformBuy(){
                $("div.form tbody tr").removeClass('none');
                $("div.form tbody tr").each(function(){
                    $(".date-warn").text("有效期");
                    if($(this).index()>10){
                        $(this).addClass('none');
                        $("div.form tbody tr:last-child").removeClass('none');
                    };
                  });
        }
        $(document).ready(function() {
            //自动完成输入提示
            var auto = new AMap.Autocomplete({
                    input: "suggestId"
                }); 
            
            var editor = UE.getEditor('editor', {
                imageScaleEnabled :false,
                enableAutoSave :false,   
                initialFrameWidth : 590,
                initialFrameHeight : 420,
                wordCount : false,
                elementPathEnabled :false,
                autoHeightEnabled : false
            });
         	
           editor.ready(function() { 
           	editor.setContent(''); 
       		});

       	  editor.addListener("contentchange", function() {
       	        $("#introdution").html(editor.getContent());
       	        contentStr = $("#introdution").html(editor.getContent()).html();
       	        console.log(contentStr);
       	    });
         
           
           editor.addListener('afterExecCommand',function(t, e, arg){
           	afterUploadImage(e);console.log(e);
           	});
           	//2、单张图片上传返回的e为inserthtml，多张图片上传返回的e为insertimage，执行插入段落命令。
           	function afterUploadImage() {
           	if(arguments[0]=="inserthtml" || arguments[0]=="insertimage"){
           		editor.execCommand( 'insertparagraph' );
           	}
           }
        
            laydate.render({
              elem: '#date',
              theme: '#59BCE3',
              done: function(value, date){ //监听日期被切换
                console.log(value);
                if(!value&&value=="") {
                	$("#dateError").text("日期不能为空");
            		$("#dateError").css("display", "inline-block");
                }else{
                	$("#dateError").css("display", "none");
                }
              }
            });
            
            
            /*  
             * 4. 表单提交时进行校验  
             */
            $("#btn_register").click(function() {
                //商品名称
                var name = $("#forBuy").val();
                //商品类型Id
                var categoryId =  $("#forType").attr("title");
                //货物数量
                var num = Number($("#goodsQuantity").val());
                //数量单位
                 var company = $("#unit").val();
                //收货地址/
                var address = $("#suggestId").val();
                //报价截至时间
                var endTime = $("#date").val();
                //所在地要求
                var locationAddress = $("#addressRequire").val();
                //其他说明
                var explain = $("#otherText").val();
                //图片src数组
                var imgUrl = getImgSrc();
                
                // 交易方式  1表示 现货求购、2表示求购黄页、3表示平台代买
                var status = Number($("input[name='qg']:checked").val());
                //目标单价 1电议、 2具体值
                var target = Number($("input[name='mbdj']:checked").val());
                //目标单价中的具体值
                var price = Number($("#money").val());
                //运送方式 1送货上门、 2上门自提 
                var mode = Number($("input[name='ysfs']:checked").val());
                //账期要求 1货到付款、 2可接受账期
                var bill = Number($("input[name='zqyq']:checked").val());
                //发票要求 1可提供发票、 2无要求
                var invoice = Number($("input[name='fpyq']:checked").val());
                
                var bool = true; //表示校验通过  
                var ck = document.getElementById('jt').checked;
                if(ck){
                    if(!validateMoney()) {
                        bool = false;
                    }else{
                        $("#moneyError").css("display", "none");
                    }
                }
                if(!validateForBuy()) {
                    bool = false;
                }
                if(!typeTips()) {
                    bool = false;
                }
                 if(!unitTips()) {
                    bool = false;
                } 
                if(!validateGoodsQuantity()) {
                    bool = false;
                }
                if(mbdjTips()) {
                	if(!price){
                		$("#moneyError").css("display", "");
                		bool = false;
                	}else{
                		$("#moneyError").css("display", "none");
                	}
                }
                if(!validateSuggestId()) {
                    bool = false;
                }
                if(!endTime) {
                	$("#dateError").text("日期不能为空");
            		$("#dateError").css("display", "inline-block");
            		bool=false;
                }else{
                	$("#dateError").css("display", "none");
                }
                if(imgUrl.length==0){
                	$("#Pic_pass p").addClass("warn-color");
                	bool = false;
                }

                if (bool == true) {
                	$.ajax({
                        type: "post",
                        url: "<c:url value="/buymanage/toPlatformbuySave.do"/>",
                        data: {
                            status : status,
                            name : name,
                            num : num ,
                            company : company,
                            categoryId : categoryId,
                            address : address,
                            endTime : endTime,
                            locationAddress : locationAddress,
                            explain : explain,
                            imgUrl : imgUrl,
                            target : target,
                            price : price,
                            mode : mode,
                            bill : bill,
                            invoice : invoice,
                            content:contentStr
                        },
                        cache:false,
                        dataType: "json",
                        success: function(data){
                            console.log(data);
                            if (data.msg == "1") {
                                window.location.href = "<c:url value="/buymanage/toPlatformSucces.do"/>";
                            }
                        }
                    })
                }
            });
        })
        
        </script>
    </body>
</html>
